package com.ruge._08_springboot_springdata_jpa.controller._05_query;

import lombok.AllArgsConstructor;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.NamedQueries;

import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.util.Date;
@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@NamedQueries({
        //name:为JPQL命名,为其他地方使用来指定名称
        //query:执行对应JPQL
        @NamedQuery(name = "selectAll", query = "SELECT e FROM QueryEmployeeModel e"),
        @NamedQuery(name = "selectByAge", query = "SELECT e FROM QueryEmployeeModel e WHERE e.age > ?1")
})

@Cacheable//需要使用二级缓存
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE,region = "sampleCache1")
@Table(name = "t_query_employee")
public class QueryEmployeeModel {
    @Id
    @GeneratedValue
    private int id;
    private String name;
    private Integer age;
    private Date hireDate = new Date();
    @Version
    private Integer version;

    public QueryEmployeeModel(String name, Integer age, Integer version) {
        this.name = name;
        this.age = age;
        this.version = version;
    }
}